package org.lynn.montecarlo;

import java.awt.*;

/**
 * @author linzou@linkdoc.com
 * @ClassName: MonterCarloExperiment
 * @Description:
 * @date 2019/6/24 9:10 PM
 */
public class MonterCarloExperiment {

    private int squareSide;
    private int N;


    public MonterCarloExperiment(int squareSide, int n) {

        if (squareSide <= 0 || n <= 0) {
            throw new IllegalArgumentException("squareSide and N must larger than 0");
        }

        this.squareSide = squareSide;
        N = n;
    }

    public void run() {
        Circle circle = new Circle(squareSide / 2, squareSide / 2, squareSide / 2);
        MonterCarloData data = new MonterCarloData(circle);

        for (int i = 0; i < N; i++) {

            if (i % 100 == 0) {
                System.out.println(data.estimatePi());
            }

            int x = (int) (Math.random() * squareSide);
            int y = (int) (Math.random() * squareSide);

            data.addPoint(new Point(x, y));


        }
    }

    public static void main(String[] args) {


        int squareSide = 800;
        int N = 1000;

        MonterCarloExperiment exp = new MonterCarloExperiment(squareSide, N);
        exp.run();


    }
}
